package com.hntxk.cqzd.statistics.action;

import com.hntxk.cqzd.common.action.CqzdBaseController;
import com.hntxk.cqzd.statistics.model.VisitCount;
import com.hntxk.cqzd.statistics.service.VisitCountService;
import com.hntxk.cqzd.statistics.service.impl.VisitCountServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @Description: 患者就诊人次统计<br>
 * @Project: SP <br>
 * @date 2019/6/4 09:35 <br>
 * @author <a href="huangbiquan@hotmail.com">Huang.Biquan</a>
 */
@Api(value="患者就诊人次统计", tags={"[CQZD]患者就诊人次统计"})
@Controller
@RequestMapping("cqzd/stat")
@Slf4j
public class VisitCountController extends CqzdBaseController {

    /** 查询页面的path */

    private final static String LIST_JSP_PATH = "cqzd/statistics/visit_count";

    private final VisitCountService visitCountService;
    @Autowired
    public VisitCountController(@Qualifier("visitService") VisitCountService visitCountService) {
        super(visitCountService,LogManager.getLogger(VisitCountController.class));
        this.visitCountService = visitCountService;
    }

    /**
     * @return 患者人次信息统计页面
     */
    @ApiOperation(value="患者人次信息统计页面")
    @GetMapping(value = "/visit_count")
    public String index() {
       return LIST_JSP_PATH;
    }

    /**
     * 按年、季、月、周、日查询患者人次统计信息
     * @param model
     * @param request
     * @return
     */
    @ApiOperation("查询患者人次日统计信息")
    @RequestMapping(value = "/queryVisitCountByDay",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryVisitCountByDay(@ModelAttribute VisitCount model, HttpServletRequest request) {

        try {
            //设置分页信息
            //model.setPagination(request);
            model.getPagination().setPageSize(50);
            String list = toJson(model, visitCountService.query2Json(VisitCountServiceImpl.MAPPER_NAMESPACE + "selectVisitByDay", model, false));

            return list;
        } catch (Exception e) {

            return getError(e);
        }
    }

    @ApiOperation("查询患者人次周统计信息")
    @RequestMapping(value = "/queryVisitCountByWeek",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryVisitCountByWeek(@ModelAttribute VisitCount model, HttpServletRequest request) {

        try {
            //设置分页信息
            //model.setPagination(request);
            model.getPagination().setPageSize(50);
            String list = toJson(model, visitCountService.query2Json(VisitCountServiceImpl.MAPPER_NAMESPACE + "selectVisitByWeek", model, false));

            return list;
        } catch (Exception e) {

            return getError(e);
        }
    }

    @ApiOperation("查询患者人次月统计信息")
    @RequestMapping(value = "/queryVisitCountByMonth",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryVisitCountByMonth(@ModelAttribute VisitCount model, HttpServletRequest request) {

        try {
            //设置分页信息
            //model.setPagination(request);
            model.getPagination().setPageSize(50);
            String list = toJson(model, visitCountService.query2Json(VisitCountServiceImpl.MAPPER_NAMESPACE + "selectVisitByMonth", model, false));

            return list;
        } catch (Exception e) {

            return getError(e);
        }
    }

    @ApiOperation("查询患者人次季统计信息")
    @RequestMapping(value = "/queryVisitCountByQuarter",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryVisitCountByQuarter(@ModelAttribute VisitCount model, HttpServletRequest request) {

        try {
            //设置分页信息
            model.setPagination(request);
            String list = toJson(model, visitCountService.query2Json(VisitCountServiceImpl.MAPPER_NAMESPACE + "selectVisitByQuarter", model, false));

            return list;
        } catch (Exception e) {

            return getError(e);
        }
    }


    @ApiOperation("查询患者人次年统计信息")
    @RequestMapping(value = "/queryVisitCountByYear",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryVisitCountByYear(@ModelAttribute VisitCount model, HttpServletRequest request) {

        try {
            //设置分页信息
            //model.setPagination(request);
            model.getPagination().setPageSize(50);
            String list = toJson(model, visitCountService.query2Json(VisitCountServiceImpl.MAPPER_NAMESPACE + "selectVisitByYear", model, false));

            return list;
        } catch (Exception e) {

            return getError(e);
        }
    }


}
